package com.hairline.hairlinemarket.service.impl;

import com.hairline.hairlinemarket.bean.MarketGoodsSpecification;
import com.hairline.hairlinemarket.bean.MarketGoodsSpecificationExample;
import com.hairline.hairlinemarket.mapper.MarketGoodsSpecificationMapper;
import com.hairline.hairlinemarket.service.GoodsSpecificationService;
import org.apache.shiro.crypto.hash.Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author:杨小凯
 * Date:2023-04-21 7:27
 * Description:<描述>
 */
@Service
public class GoodsSpecificationServiceImpl implements GoodsSpecificationService {
    @Autowired
    private MarketGoodsSpecificationMapper goodsSpecificationMapper;
    @Override
    public List<Map> queryByGoodsId(Integer id) {
        List<Map> list =new ArrayList<>();
        List nameList = new ArrayList();
        List valueList= new ArrayList();
        MarketGoodsSpecificationExample goodsSpecificationExample = new MarketGoodsSpecificationExample();
        MarketGoodsSpecificationExample.Criteria criteria = goodsSpecificationExample.createCriteria();
        criteria.andGoodsIdEqualTo(id);
        List<MarketGoodsSpecification> marketGoodsSpecifications = goodsSpecificationMapper.selectByExample(goodsSpecificationExample);
        for (MarketGoodsSpecification marketGoodsSpecification : marketGoodsSpecifications) {
            nameList.add(marketGoodsSpecification.getSpecification());
        }

        //HashMap<Object, Object> map = new HashMap<>();


        if(nameList.size()!=0&&nameList!=null){
            for (Object e : nameList) {
                for (MarketGoodsSpecification marketGoodsSpecification : marketGoodsSpecifications) {
                    if (e.equals(marketGoodsSpecification.getSpecification())){
                        valueList.add(marketGoodsSpecification);
                    }
                }
                HashMap<Object, Object> map = new HashMap<>();
                map.put("name",e);
                map.put("valueList", valueList);
                list.add(map);
            }

            //map.put("name","规格");
            //map.put("valueList", valueList);
        }

        return list;
    }
}
